#Set this in local.mk
#PROGRAM = main

SETUP_WEB := $(shell python3 ../../common/embed.py setup.html > setup.html.h)

EXTRA_COMPONENTS = \
	extras/sntp \
	extras/dhcpserver \
    extras/rboot-ota \
	$(abspath ../../../external_libs/wolfssl) \
	$(abspath ../../../external_libs/http-parser) \
	$(abspath ../../../libs/form_urlencoded) \
	$(abspath ../../../libs/adv_logger) \
	$(abspath ../../../libs/timers_helper)

FLASH_SIZE ?= 1
FLASH_MODE = dout
FLASH_SPEED = 40

EXTRA_WOLFSSL_CFLAGS = \
	-DWOLFSSL_USER_SETTINGS \
	-DWOLFSSL_STATIC_RSA \
	-DWOLFSSL_SHA384 \
	-DWOLFSSL_SHA512 \
	-DUSE_SLOW_SHA \
	-DUSE_SLOW_SHA2 \
	-DUSE_SLOW_SHA256 \
	-DUSE_SLOW_SHA512 \
	-DGCM_SMALL \
	-DRSA_LOW_MEM \
	-DHAVE_AESGCM \
	-DHAVE_ECC \
	-DHAVE_ECC_VERIFY \
	-DHAVE_ECC_KEY_IMPORT \
	-DHAVE_TLS_EXTENSIONS \
	-DHAVE_ECC_DHE \
 	-DHAVE_SUPPORTED_CURVES \
	-DHAVE_SNI \
	-DNO_MD5 \
	-DNO_FILESYSTEM \
	-DNO_WRITEV \
	-DNO_WOLFSSL_SERVER \
	-DNO_RABBIT \
	-DNO_DH \
	-DNO_PWDBASED \
	-DNO_DES3 \
	-DNO_ERROR_STRINGS \
	-DNO_OLD_TLS \
	-DNO_RC4 \
	-DNO_PSK \
	-DNO_MD4 \
	-DNO_HC128 \
	-DNO_DEV_RANDOM \
	-DNO_SESSION_CACHE \
    -DNO_DSA \
#	-DHAVE_ONE_TIME_AUTH \
# 	-DHAVE_CHACHA \
# 	-DHAVE_POLY1305 \
#	-DWOLFSSL_SHA3 \
# 	-DWOLFSSL_SHA224 \
#	-DHAVE_ECC384 \
#	-DHAVE_ECC_SIGN \
#	-DDEBUG_WOLFSSL \
#   -DNO_SHA \
#	-DLARGE_STATIC_BUFFERS \
#	-DSTATIC_CHUNKS_ONLY \
#	-DRECORD_SIZE=1024 \
#	-DNO_CODING \
#	-DNO_INLINE \
#	-DBUILD_TLS_RSA_WITH_AES_128_GCM_SHA256 \

EXTRA_CFLAGS += $(EXTRA_WOLFSSL_CFLAGS)

# Max HAA OTA MAIN Installer firmware size is 397296 bytes

EXTRA_CFLAGS += -Os

EXTRA_CFLAGS += -Wall -std=gnu99
EXTRA_CFLAGS += -Wextra -Wno-unused-parameter
#EXTRA_CFLAGS += -Wpedantic

EXTRA_CFLAGS += -DSPIFLASH_HOMEKIT_BASE_ADDR=0xF2000
EXTRA_CFLAGS += -DHAA_CHIP_NAME=\"esp8266\"

EXTRA_CFLAGS += -DTCP_MSS=1460
EXTRA_CFLAGS += -DTCP_WND=5840
EXTRA_CFLAGS += -DTCP_SND_BUF=5840
EXTRA_CFLAGS += -DLWIP_WND_SCALE=1 -DTCP_RCV_SCALE=0

EXTRA_CFLAGS += -DLWIP_NETIF_HOSTNAME=1
EXTRA_CFLAGS += -DARP_TABLE_SIZE=10
EXTRA_CFLAGS += -DDNS_TABLE_SIZE=4
EXTRA_CFLAGS += -DDNS_MAX_SERVERS=2
EXTRA_CFLAGS += -DDNS_MAX_RETRIES=2
EXTRA_CFLAGS += -DDHCP_DOES_ARP_CHECK=0
#EXTRA_CFLAGS += -DCHECKSUM_CHECK_UDP=0

EXTRA_CFLAGS += -DDHCP_SERVER_MAX_LEASES=2

EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0

#EXTRA_CFLAGS += -DconfigMAX_TASK_NAME_LEN=7
EXTRA_CFLAGS += -DconfigCHECK_FOR_STACK_OVERFLOW=2
EXTRA_CFLAGS += -DconfigMINIMAL_STACK_SIZE=256
EXTRA_CFLAGS += -DconfigTIMER_TASK_PRIORITY=\(tskIDLE_PRIORITY+5\)
EXTRA_CFLAGS += -DconfigTIMER_QUEUE_LENGTH=10
EXTRA_CFLAGS += -DconfigTIMER_TASK_STACK_DEPTH=600

#EXTRA_CFLAGS += -DLWIP_DEBUG

include $(abspath ../../../sdk/esp-open-rtos-rsf/common.mk)

sign:
	../../common/ota_sign.sh

monitor:
	$(FILTEROUTPUT) --port $(ESPPORT) --baud 115200 --elf $(PROGRAM_OUT)
